<?php

use yii\helpers\Html;
use yii\grid\GridView;
use mdm\admin\components\Helper;
use backend\models\AuthAssignment;
/* @var $this yii\web\View */
/* @var $searchModel backend\controllers\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '用户列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?php   if(Helper::checkRoute('create')) {?>
    <p>
        <?= Html::a('创建用户', ['signup'], ['class' => 'btn btn-success']) ?>
    </p>
<?php } ?>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
           // ['class' => 'yii\grid\SerialColumn'],

           'id',
            'username',
            'realname',
//            'auth_key',
//            'password_hash',
            //'password_reset_token',
            'telphone',
            'email:email',
            //'status',
            //'created_at',
            //'updated_at',
            ['label'=>'角色','value'=>function($model){
                $AuthAssignment=new AuthAssignment();
                $role = $AuthAssignment->find()->where(['user_id'=>$model->id])->One();
                return !empty($role) ? $role->item_name :'待分配';
            }],
            ['class' => 'yii\grid\ActionColumn',  'template'=>Helper::filterActionColumn('{update}{delete}')],
        ],
    ]); ?>
</div>
